﻿using Microsoft.AspNetCore.Mvc;
using SD.Infrastructure.DTOBase;
using SD.Toolkits.AspNetCore.Attributes;
using SlamDunk.MES.IAppService.DTOs.Inputs;
using SlamDunk.MES.IAppService.DTOs.Outputs.FoundationContext;
using SlamDunk.MES.IAppService.Interfaces;
using SlamDunk.ValueObjects.Enums;
using System;
using System.Collections.Generic;

namespace SlamDunk.MES.AppService.Host.Controllers
{
    /// <summary>
    /// 基础定义服务WebApi接口
    /// </summary>
    [ApiController]
    [Route("Api/[controller]/[action]")]
    public class FoundationController : ControllerBase
    {
        #region # 字段及构造器

        /// <summary>
        /// 基础定义服务契约接口
        /// </summary>
        private readonly IFoundationContract _foundationContract;

        /// <summary>
        /// 依赖注入构造器
        /// </summary>
        public FoundationController(IFoundationContract foundationContract)
        {
            this._foundationContract = foundationContract;
        }

        #endregion


        //命令部分

        #region # 创建工厂模型 —— void CreateFacility(Guid? parentNodeId, string facilityNo...
        /// <summary>
        /// 创建工厂模型
        /// </summary>
        /// <param name="parentNodeId">上级节点Id</param>
        /// <param name="facilityNo">工厂模型编号</param>
        /// <param name="facilityName">工厂模型名称</param>
        /// <param name="facilityLevel">工厂模型层次</param>
        /// <param name="facilityType">工厂模型类型</param>
        /// <param name="description">描述</param>
        [HttpPost]
        [WrapPostParameters]
        public void CreateFacility(Guid? parentNodeId, string facilityNo, string facilityName, FacilityLevel facilityLevel, FacilityType? facilityType, string description)
        {
            this._foundationContract.CreateFacility(parentNodeId, facilityNo, facilityName, facilityLevel, facilityType, description);
        }
        #endregion

        #region # 修改工厂模型 —— void UpdateFacility(Guid facilityId, string facilityName...
        /// <summary>
        /// 修改工厂模型
        /// </summary>
        /// <param name="facilityId">工厂模型Id</param>
        /// <param name="facilityName">工厂模型名称</param>
        /// <param name="description">描述</param>
        [HttpPost]
        [WrapPostParameters]
        public void UpdateFacility(Guid facilityId, string facilityName, string description)
        {
            this._foundationContract.UpdateFacility(facilityId, facilityName, description);
        }
        #endregion

        #region # 删除工厂模型 —— void RemoveFacility(Guid facilityId)
        /// <summary>
        /// 删除工厂模型
        /// </summary>
        /// <param name="facilityId">工厂模型Id</param>
        [HttpPost]
        [WrapPostParameters]
        public void RemoveFacility(Guid facilityId)
        {
            this._foundationContract.RemoveFacility(facilityId);
        }
        #endregion

        #region # 创建工位 —— void CreateWorkStation(string workStationNo, string workStationName...
        /// <summary>
        /// 创建工位
        /// </summary>
        /// <param name="workStationNo">工位编号</param>
        /// <param name="workStationName">工位名称</param>
        /// <param name="facilityId">工厂模型Id</param>
        /// <param name="description">描述</param>
        [HttpPost]
        [WrapPostParameters]
        public void CreateWorkStation(string workStationNo, string workStationName, Guid? facilityId, string description)
        {
            this._foundationContract.CreateWorkStation(workStationNo, workStationName, facilityId, description);
        }
        #endregion

        #region # 修改工位 —— void UpdateWorkStation(Guid workStationId, string workStationNo...
        /// <summary>
        /// 修改工位
        /// </summary>
        /// <param name="workStationId">工位Id</param>
        /// <param name="workStationNo">工位编号</param>
        /// <param name="workStationName">工位名称</param>
        /// <param name="facilityId">工厂模型Id</param>
        /// <param name="description">描述</param>
        [HttpPost]
        [WrapPostParameters]
        public void UpdateWorkStation(Guid workStationId, string workStationNo, string workStationName, Guid? facilityId, string description)
        {
            this._foundationContract.UpdateWorkStation(workStationId, workStationNo, workStationName, facilityId, description);
        }
        #endregion

        #region # 删除工位 —— void RemoveWorkStation(Guid workStationId)
        /// <summary>
        /// 删除工位
        /// </summary>
        /// <param name="workStationId">工位Id</param>
        [HttpPost]
        [WrapPostParameters]
        public void RemoveWorkStation(Guid workStationId)
        {
            this._foundationContract.RemoveWorkStation(workStationId);
        }
        #endregion

        #region # 创建计量单位组 —— void CreateMeasureUnitGroup(string groupNo, string groupName...
        /// <summary>
        /// 创建计量单位组
        /// </summary>
        /// <param name="groupNo">计量单位组编号</param>
        /// <param name="groupName">计量单位组名称</param>
        /// <param name="groupDescription">描述</param>
        /// <param name="measureUnitParams">计量单位参数模型集</param>
        [HttpPost]
        [WrapPostParameters]
        public void CreateMeasureUnitGroup(string groupNo, string groupName, string groupDescription, IEnumerable<MeasureUnitParam> measureUnitParams)
        {
            this._foundationContract.CreateMeasureUnitGroup(groupNo, groupName, groupDescription, measureUnitParams);
        }
        #endregion

        #region # 修改计量单位组 —— void UpdateMeasureUnitGroup(Guid measureUnitGroupId, string groupName...
        /// <summary>
        /// 修改计量单位组
        /// </summary>
        /// <param name="measureUnitGroupId">计量单位组Id</param>
        /// <param name="groupName">计量单位组名称</param>
        /// <param name="description">描述</param>
        /// <param name="measureUnitParams">计量单位参数模型集</param>
        [HttpPost]
        [WrapPostParameters]
        public void UpdateMeasureUnitGroup(Guid measureUnitGroupId, string groupName, string description, IEnumerable<MeasureUnitParam> measureUnitParams)
        {
            this._foundationContract.UpdateMeasureUnitGroup(measureUnitGroupId, groupName, description, measureUnitParams);
        }
        #endregion

        #region # 删除计量单位组 —— void RemoveMeasureUnitGroup(Guid measureUnitGroupId)
        /// <summary>
        /// 删除计量单位组
        /// </summary>
        /// <param name="measureUnitGroupId">计量单位组Id</param>
        [HttpPost]
        [WrapPostParameters]
        public void RemoveMeasureUnitGroup(Guid measureUnitGroupId)
        {
            this._foundationContract.RemoveMeasureUnitGroup(measureUnitGroupId);
        }
        #endregion


        //查询部分

        #region # 获取工厂模型列表 —— IEnumerable<FacilityInfo> GetFacilities(string keywords...
        /// <summary>
        /// 获取工厂模型列表
        /// </summary>
        /// <param name="keywords">关键字</param>
        /// <param name="facilityLevel">工厂模型层次</param>
        /// <param name="facilityType">工厂模型类型</param>
        /// <param name="parentNodeId">上级节点Id</param>
        /// <returns>工厂模型列表</returns>
        [HttpGet]
        public IEnumerable<FacilityInfo> GetFacilities(string keywords, FacilityLevel? facilityLevel, FacilityType? facilityType, Guid? parentNodeId)
        {
            return this._foundationContract.GetFacilities(keywords, facilityLevel, facilityType, parentNodeId);
        }
        #endregion

        #region # 获取根级工厂模型列表 —— IEnumerable<FacilityInfo> GetRootFacilities()
        /// <summary>
        /// 获取根级工厂模型列表
        /// </summary>
        /// <returns>工厂模型列表</returns>
        [HttpGet]
        public IEnumerable<FacilityInfo> GetRootFacilities()
        {
            return this._foundationContract.GetRootFacilities();
        }
        #endregion

        #region # 分页获取工位列表 —— PageModel<WorkStationInfo> GetWorkStationsByPage(...
        /// <summary>
        /// 分页获取工位列表
        /// </summary>
        /// <param name="keywords">关键字</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页容量</param>
        /// <returns>工位列表</returns>
        [HttpGet]
        public PageModel<WorkStationInfo> GetWorkStationsByPage(string keywords, int pageIndex, int pageSize)
        {
            return this._foundationContract.GetWorkStationsByPage(keywords, pageIndex, pageSize);
        }
        #endregion

        #region # 分页获取计量单位组列表 —— PageModel<MeasureUnitGroupInfo> GetMeasureUnitGroupsByPage(...
        /// <summary>
        /// 分页获取计量单位组列表
        /// </summary>
        /// <param name="keywords">关键字</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页容量</param>
        /// <returns>计量单位组列表</returns>
        [HttpGet]
        public PageModel<MeasureUnitGroupInfo> GetMeasureUnitGroupsByPage(string keywords, int pageIndex, int pageSize)
        {
            return this._foundationContract.GetMeasureUnitGroupsByPage(keywords, pageIndex, pageSize);
        }
        #endregion

        #region # 分页获取计量单位列表 —— PageModel<MeasureUnitInfo> GetMeasureUnitsByPage(string keywords...
        /// <summary>
        /// 分页获取计量单位列表
        /// </summary>
        /// <param name="keywords">关键字</param>
        /// <param name="unitGroupId">计量单位组Id</param>
        /// <param name="isMaster">是否主计量单位</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页容量</param>
        /// <returns>计量单位列表</returns>
        [HttpGet]
        public PageModel<MeasureUnitInfo> GetMeasureUnitsByPage(string keywords, Guid? unitGroupId, bool? isMaster, int pageIndex, int pageSize)
        {
            return this._foundationContract.GetMeasureUnitsByPage(keywords, unitGroupId, isMaster, pageIndex, pageSize);
        }
        #endregion

        #region # 获取计量单位列表 —— IEnumerable<MeasureUnitInfo> GetMeasureUnits(Guid measureGroupId)
        /// <summary>
        /// 获取计量单位列表
        /// </summary>
        /// <param name="measureGroupId">计量单位组Id</param>
        /// <returns>计量单位列表</returns>
        [HttpGet]
        public IEnumerable<MeasureUnitInfo> GetMeasureUnits(Guid measureGroupId)
        {
            return this._foundationContract.GetMeasureUnits(measureGroupId);
        }
        #endregion

        #region # 是否存在计量单位 —— bool ExistMeasureUnit(Guid? measureUnitId, string measureUnitNo)
        /// <summary>
        /// 是否存在计量单位
        /// </summary>
        /// <param name="measureUnitId">计量单位Id</param>
        /// <param name="measureUnitNo">计量单位编号</param>
        /// <returns>是否存在</returns>
        [HttpGet]
        public bool ExistMeasureUnit(Guid? measureUnitId, string measureUnitNo)
        {
            return this._foundationContract.ExistMeasureUnit(measureUnitId, measureUnitNo);
        }
        #endregion
    }
}
